cmake_minimum_required (VERSION 2.6)

set(EXAMPLE_NAME "python_api_example")

# --- Configure Sourcetrail Project File ---

add_custom_target(
	${EXAMPLE_NAME} ALL
	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/src/example.py ${CMAKE_CURRENT_BINARY_DIR}/example.py
)

add_dependencies(${EXAMPLE_NAME} _${PYTHON_BINDING_TARGET_NAME})

if (MSVC)
	STRING(REGEX REPLACE "/" "\\\\" BACKSLASHED_PYTHON_BINDING_OUTPUT_DIR ${PYTHON_BINDING_OUTPUT_DIR})
	STRING(REGEX REPLACE "/" "\\\\" BACKSLASHED_CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

	add_custom_command(
		TARGET ${EXAMPLE_NAME} POST_BUILD
		COMMAND xcopy \"${BACKSLASHED_PYTHON_BINDING_OUTPUT_DIR}\\$(Configuration)\\_sourcetraildb*\" \"${BACKSLASHED_CMAKE_CURRENT_BINARY_DIR}\" /Y
	)
	add_custom_command(
		TARGET ${EXAMPLE_NAME} POST_BUILD
		COMMAND xcopy \"${BACKSLASHED_PYTHON_BINDING_OUTPUT_DIR}\\sourcetraildb.py\" \"${BACKSLASHED_CMAKE_CURRENT_BINARY_DIR}\" /Y
	)
else()
	add_custom_command(
		TARGET ${EXAMPLE_NAME} POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_BINDING_OUTPUT_DIR}/_sourcetraildb* ${CMAKE_CURRENT_BINARY_DIR}
		COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_BINDING_OUTPUT_DIR}/sourcetraildb.py ${CMAKE_CURRENT_BINARY_DIR}
	)

	if (APPLE)
		add_custom_command(
			TARGET ${EXAMPLE_NAME} POST_BUILD
			COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/_sourcetraildb.dylib ${CMAKE_CURRENT_BINARY_DIR}/_sourcetraildb.so
		)
	endif()
endif()


set(PYTHON_API_EXAMPLE_DATA_PATH "${CMAKE_CURRENT_SOURCE_DIR}/data")

configure_file(
	"${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_NAME}.srctrlprj.in"
	"${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE_NAME}.srctrlprj"
)
